//
//  cmd_packet.h
//  CmdPacket
//
//  Created by hua on 2021/12/12.
//

#ifndef cmd_packet_h
#define cmd_packet_h

#include <stdio.h>
#include <stdint.h>

typedef struct CmdPacket {
    uint8_t begin;
    uint8_t len; //
    uint8_t data[0]; // 后面的内容自定义 该模块只负责编码
//    uint8_t crc8;
//    uint8_t end;
} CmdPacket;


// 转义字符可以自定义
#define CMD_PACKET_BEGIN 0x05
#define CMD_PACKET_BEGIN_REPLACE 0x04
#define CMD_PACKET_GENG 0x01
#define CMD_PACKET_GENG_REPLACE 0x00
#define CMD_PACKET_ENG 0x03
#define CMD_PACKET_ENG_REPLACE 0x02


CmdPacket *pkg_decode(uint8_t *out, int size);
int pkg_encode(uint8_t *out, CmdPacket *pkg);

int pkg_send(CmdPacket * pkg, uint8_t *out);
CmdPacket *pkg_recv(uint8_t *data, int size);


#endif /* cmd_packet_h */
